package com.zm.demo.core.leetcode;

import static java.lang.System.out;

/**
 * @author zoum
 * @create 2020/1/16 18:06
 */
public class RemoveDuplicates {


    public static int removeDuplicates(int[] nums) {
        int count=0;
        int first = -1;
        int changeIndex = -1;
        for(int i=0; i < nums.length-1-count; i++){
            if (first >=0 && nums[first] != nums[i]){
                int temp = nums[changeIndex];
                nums[changeIndex] = nums[i];
                nums[i] = temp;
                first = changeIndex;
                changeIndex++;
            }else if (nums[i] == nums[i+1]){
                first = i;
                i++;
                changeIndex = i;
                count++;
            }


        }
        return nums.length - count;
    }

    public static void main(String[]args){
        out.println(removeDuplicates(new int[]{0,0,0,1,1,1,2,2,2,3,3,4,4,4,4,4,4,4}));
    }
}
